home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Applications / Alpha.5.96 folder / Tcl / SystemCode / appleEvents.tcl < prev    next >
Encoding:
Text File  |  1994-09-08  |  3.1 KB  |  104 lines  |  [TEXT/ALFA]

  1.  
  2. # make alias list to pass to AEBuild
  3. proc makeAlis {name} {
  4.     concat {[alis(«} [coerce TEXT $name -x alis] {»)]}    
  5. }
  6.  
  7.  
  8.  
  9. # Queued replies are passed through AEPrint and then to this routine.
  10. proc handleReply {rep} {
  11.     global ALPHA lastReply
  12. #    switchTo $ALPHA
  13.     set lastReply $rep
  14. }
  15.  
  16.  
  17. # Return an object record specifying the desired think project file.
  18. proc fileObject {name} {
  19.     join [concat {obj\{want:type('SFIL'), from:'null'(), form:'name', seld:“} [file tail $name] {”\}}] ""
  20. }
  21.  
  22.  
  23. proc sendOpenEvent {filler appname fname} {
  24.     AEBuild $appname aevt odoc "----" [concat {[alis(«} [coerce TEXT $fname -x alis] {»)]}]
  25. }
  26.  
  27.  
  28. #================================================================================
  29. # Most of the routines below by Tom Pollard
  30. #================================================================================
  31.  
  32. proc AEAbsPos {posName} {
  33. # (would like to be able to use 'first' and 'last' as well, but haven't yet
  34. # figured out the correct AEBuild syntax.  "seld:abso('firs')" doesn't work.)
  35.     if {$posName > 0} {
  36.         return "form:indx, seld:long($posName)"
  37.     } else {
  38.         error "AEAbsPos: bad argument"
  39.     }
  40. }
  41. proc AEName {name} {
  42.     return "form:'name', seld:[curlyq $name]"
  43. }
  44. proc AEWinByName {name} {
  45.     return "obj{want:type('cwin'), from:'null'(), [AEName $name] } "
  46. }
  47. proc AEWinByPos {absPos} {
  48.     return "obj{want:type('cwin'), from:'null'(), [AEAbsPos $absPos] } "
  49. }
  50. proc AELineRange {absPos1 absPos2} {
  51.     set lineObj1 "obj{ want:type('clin'), from:'ccnt'(), [AEAbsPos $absPos1] }"
  52.     set lineObj2 "obj{ want:type('clin'), from:'ccnt'(), [AEAbsPos $absPos2] }"
  53.     return "form:'rang', seld:rang{star:$lineObj1, stop:$lineObj2 } "
  54. }
  55.  
  56. # Quit an application.
  57. proc sendQuitEvent {appname} {
  58.     AEBuild $appname "aevt" "quit" 
  59. }
  60.  
  61. # Close one of an application's windows, designated by number.
  62. proc sendCloseWinNum {appname num} {
  63.     AEBuild $appname "core" "clos" "----" [AEWinByPos $num]
  64. }
  65.  
  66. # Close one of an application's windows, designated by name.
  67. proc sendCloseWinName {appname name} {
  68.     AEBuild $appname "core" "clos" "----" [AEWinByName $name]
  69. }
  70.  
  71. # Obtain the number of lines in one of an application's
  72. # windows, designated by name.
  73. proc sendCountLines {appname name} {
  74.     set winObj [AEWinByName $name]
  75.     set res [AEBuild -r $appname "core" "cnte" "----" $winObj kocl type('clin')]    
  76.     if {[regexp {:(.*)\}} $res allofit nlines]} {
  77.         return $nlines
  78.     } else {
  79.         return 0
  80.     }
  81. }
  82.  
  83. # Get a selected range of lines from one of an application's
  84. # windows, designated by name.  If $last is missing, then a single
  85. # line is returned; if both $first and $last are missing, then
  86. # the complete window contents are returned.
  87. proc sendGetText {appname name {first {missing}} {last {missing}}} {
  88.     global ALPHA
  89.     set winObj [AEWinByName $name]
  90.     if {$first != "missing"} {
  91.         if {$last != "missing"} {
  92.             set rangDesc [AELineRange $first $last]
  93.         } else {
  94.             set rangDesc [AEAbsPos $first]
  95.         }
  96.         set objDesc "obj{want:type('clin'), from:$winObj, $rangDesc }"
  97.     } else {
  98.         set objDesc "obj{want:type('ctxt'), from:$winObj, form:'indx', seld:abso('all') }"
  99.     }
  100.     set res [AEBuild -r $appname "core" "getd" "----" $objDesc]    
  101.     if {![regexp {“.*”} $res text]} { set text {} }
  102.     return [string trim $text {“”}]
  103. }
  104.